package com.xxx.lambda;

import java.awt.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.function.Consumer;
import java.util.function.IntSupplier;
import java.util.function.Predicate;
import java.util.function.Supplier;

/**
 * @version v1.0
 * @Description
 * @Author admin
 * @date 2021/7/26  11:05
 * @Copyright
 */
public class Lam1 {
    public static void main(String[] args) {
        // m1();
        // m2();
        // m3();
        // m4();
        ArrayList<Integer> integers = new ArrayList<>();
        Supplier<Integer> supplier = new Supplier<Integer>() {
            @Override
            public Integer get() {
                return 857;
            }
        };
        //System.out.println("supplier = " + supplier.get());
        Supplier<Integer> callable = () -> {
            return 857;
        };
        System.out.println("supplier = " + supplier.get());


    }

    private static void m4() {
        final Predicate<String> predicate = new Predicate<String>() {
            @Override
            public boolean test(String s) {
                return s.equals("abc");
            }
        };
        // System.out.println(predicate.test("acbdefg"));
        Predicate abc = s -> s.equals("abc");
        System.out.println(predicate.test("acbdefg"));
    }

    private static void m3() {
        Consumer<String> consumer = new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println("s = " + s);
            }
        };
        //consumer.accept("abc");
        Consumer tConsumer = s -> {
            System.out.println("s = " + s);
        };
        consumer.accept("abccbaabccbaacbcbabacbbcbabaabcbbccbabcbcbaba");
    }

    private static void m2() {
        //匿名内部类
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("匿名内部类方式");
            }
        };
        runnable.run();
        Runnable rmb = () -> {
            System.out.println("匿名内部类方式");
        };
    }

    private static void m1() {
        ArrayList<Student> students = new ArrayList<>();
        students.add(new Student("sdfs", 55, "sfds"));
        students.add(new Student("sdfafsds", 95, "scfs"));
        students.add(new Student("sasfddfs", 65, "sfs"));
        students.add(new Student("sasfdfs", 25, "sfas"));
        students.add(new Student("sadfs", 45, "sfys"));

        students.sort(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getAge() - o2.getAge();
            }

        });

        for (Student student : students) {
            System.out.println("student = " + student.getAge());
        }
    }
}
